<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>fieldFilter</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="Preview page of Metronic Admin Theme #1 for form layouts" name="description" />
    <meta content="" name="author" />

    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.css" />
    <link href="../../global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
    <link href="../../global/css/plugins.min.css" rel="stylesheet"  type="text/css" />
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <link rel="stylesheet" href="../../custom/css/changeother.css"/>
<body>
<div class="contentPadding">
    <table class="layui-table" id="LAY_table_user" lay-filter="user"></table>
</div>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="../../global/plugins/datatables/datatables.min.js"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="layui/layui.all.js"></script>
<script src="js/template.js"></script>
<script>
    console.log(parent.currentRelationObj);
    (function () {
        //字段转换成表格数据
        var data = $.map(parent.currentRelationObj,function (v,i) {
            var flag;
            if(!parent.graph.getCell(v.dataObj.objectId+v.fkObj.fkId)){
                flag = false;
            }else {
                flag = true;
            }
            var fieldName = v.dataObj.objectChname?v.dataObj.objectChname+"(" +v.dataObj.tableName+")":v.dataObj.tableName;
            return {"fieldName" : fieldName ,"LAY_CHECKED": flag,"relationObj":v}
        });

        layui.use('table', function(){
            var table = layui.table;
            //方法级渲染
            table.render({
                elem: '#LAY_table_user'
                ,cols: [[
                    {type:'checkbox'}
                    ,{field:'fieldName', title: '表名', minWidth:80,}
                ]]
                ,id: 'testReload',
                height: 'full-20',
                data : data
                ,done :function(){

                }
            });
            //表格数据转换成字段数据
            window.getCheckRelationData = function () {
             var checkStatus = table.checkStatus('testReload'); //test即为基础参数id对应的值
             console.log(checkStatus.data); //获取选中行的数据

             var relationObj =   $.map(checkStatus.data,function (v,i) {
                    return v.relationObj;
                });
                return relationObj;
            };


        });

    })();

</script>
</body>

</html>